var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listname: -1,
    robotlist: []
  },

 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    })
    const db = wx.cloud.database()
    try {
      db.collection('menulist').where({
        id: 'robotlist'
      }).get({
        success: res => {
          var detailobj = res.data[0];
          var dataobj = JSON.parse(detailobj.data)
          this.setData({
            robotlist: dataobj
          })
          wx.hideToast();
        },
        fail: err => {
          wx.showToast({
            icon: 'none',
            title: '查询菜单失败，请检查网络'
          })
          wx.hideToast();
        }
      })
    } catch (e) {
      wx.showToast({
        title: '读取数据失败，请检查网络',
        icon: 'none',
        duration: 10000
      })
    }
  },

  

  //自定义方法
  listactive: function (e) {
    this.setData({ listname: e.currentTarget.dataset.listname })
  },
  robotrouter: function (e) {
    if(e.currentTarget.id.substring(0, 5)=='titan'){
      wx.navigateTo({
        router: 'robot',
        url: '/pages/Wrobot_titan_detail/Wrobot_titan_detail' + '?id=' + e.currentTarget.id
      })
      return false;
    }
    wx.navigateTo({
      router: 'robot',
      url: '/pages/Wrobot_detail/Wrobot_detail' + '?id=' + e.currentTarget.id
    })
  }
})